﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IPC.Communication.Framework.ModBus
{
    public class ModBusMonitorAddress
    {
        public ushort Address
        {
            get;
            set;
        }

        public event Action<ModBusMonitorAddress, short> OnWrite;

        public event Action<ModBusMonitorAddress, short, short> OnChange;

        public void SetValue(short value)
        {
            if (this.OnWrite != null)
            {
                this.OnWrite.Invoke(this, value);
            }
        }

        public void SetChangeValue(short before, short after)
        {
            if (before != after)
            {
                if (this.OnChange != null)
                {
                    this.OnChange.Invoke(this, before, after);
                }
            }
        }
    }
}
